package com.happyhome.services;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.happyhome.constants.ComTxManagerName;
import com.happyhome.dao.RoomUtilityDao;
import com.happyhome.datamodel.RoomUtility;

@Service
public class RoomUtilityServiceImpl implements RoomUtilityService {

	@SuppressWarnings("unused")
	private static final Logger logger = LoggerFactory.getLogger(RoomUtilityServiceImpl.class);

	@Autowired
	private RoomUtilityDao roomUtilityDao;

	@Override
	@Transactional(value = ComTxManagerName.COM_TRANSACTION_MANAGER)
	public RoomUtility merge(RoomUtility roomUtility) {
		return roomUtilityDao.merge(roomUtility);
	}

	@Override
	public List<Object[]> getAllUtilityByRoomId(Long roomId) {
		return roomUtilityDao.getAllUtilityByRoomId(roomId);
	}

	@Override
	@Transactional(value = ComTxManagerName.COM_TRANSACTION_MANAGER)
	public void deleteAllUtilitiesRoomUtility(Long houseId) {
		List<RoomUtility> roomUtilities = roomUtilityDao.getAllUtilitiesOfRoom(houseId);
		for(RoomUtility roomUtility: roomUtilities){
			roomUtilityDao.remove(roomUtility);
		}
	}
}
